package leetcode.editor.cn;

public class AInsertionSort implements AIOrder{
    @Override
    public void sort(int[] nums) {
        if (nums == null || nums.length < 2) {
            return;
        }

        for (int i = 1; i < nums.length; i++) {
            int cur = nums[i];
            int j = i;
            while (j > 0) {
                if (nums[j-1] > cur) {
                    nums[j] = nums[j-1];
                } else {
                    break;
                }
                j--;
            }
            nums[j] = cur;
        }
    }

    public static void main(String[] args) {
        AIOrder order = new AInsertionSort();
        int[] nums = new int[]{8, 9, 1, 7, 2, 3, 5, 4, 6, 0};
        order.sort(nums);
        System.out.println("end");
    }
}
